#include <iostream>
#include <vector>
#include <string.h>
using namespace std;


//https://www.nowcoder.com/practice/237ae40ea1e84d8980c1d5666d1c53bc?tpId=230&tqId=38965&ru=/exam/oj
const int N = 1010;
int n, V, v[N], w[N];


void Test01()
{
    int dp[N][N] = {0};
    cin >> n >> V;
    for (int i = 1; i <= n; i++)
        cin >> v[i] >> w[i];

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= V; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (j >= v[i])
                dp[i][j] = max(dp[i][j], dp[i][j - v[i]] + w[i]);
        }
    cout << dp[n][V] << endl;


    memset(dp, 0, sizeof(dp));
    for (int j = 1; j <= V; j++) dp[0][j] = -1;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= V; j++)
        {
            if (dp[i - 1][j] == -1) dp[i][j] = -1;
            else dp[i][j] = dp[i - 1][j];

            if (j >= v[i] && dp[i][j - v[i]] != -1)
                dp[i][j] = max(dp[i - 1][j], dp[i][j - v[i]] + w[i]);
        }
    cout << (dp[n][V] == -1 ? 0 : dp[n][V]);
}


void Test02()
{
    int dp[N] = { 0 };
    cin >> n >> V;
    for (int i = 1; i <= n; i++)
        cin >> v[i] >> w[i];

    for (int i = 1; i <= n; i++)
        for (int j = v[i]; j <= V; j++)
            if (j >= v[i])
                dp[j] = max(dp[j], dp[j - v[i]] + w[i]);

    cout << dp[V] << endl;


    memset(dp, 0, sizeof dp);
    for (int j = 1; j <= V; j++) dp[j] = -0x3f3f3f3f;
    for (int i = 1; i <= n; i++)
        for (int j = v[i]; j <= V; j++)
            dp[j] = max(dp[j], dp[j - v[i]] + w[i]);

    cout << (dp[V] < 0 ? 0 : dp[V]);
}

int main()
{
    Test01();
    Test02();
    return 0;
}
 